<template>
	<view class="container">
		<image :src="creator.avatar" mode="aspectFill" style="width: 100%;filter: blur(8rpx);"></image>
		<view class="head">
			<image :src="creator.avatar"></image>
			<view class="name">
				{{creator.word}}
			</view>
		</view>
		<view class="content">
			<view class="nums">
				<view class="item">
					<text>{{creator.works}}</text>作品
				</view>
				<view class="item">
					<text>{{creator.like}}</text>获赞
				</view>
				<view class="item">
					<text>{{creator.power}}</text>热度
				</view>
			</view>
			<view class="bio">
				{{creator.bio?user.creator:'暂无简介'}}
			</view>
			<view class="types-content">
				<u-sticky bgColor="#fff">
					<u-tabs :list="types" lineWidth="70" lineHeight="4" :current="currentIndex"
						:activeStyle="activeStyle" :inactiveStyle="inactiveStyle" :itemStyle="itemStyle"
						@click="changeType" lineColor="#000">
					</u-tabs>
				</u-sticky>
				<works :works="images"></works>
				<u-empty text="空的" :show="images.length==0" width="210" marginTop="300"
					icon="http://cdn.uviewui.com/uview/empty/data.png" textSize="24">
				</u-empty>
				<u-loadmore v-if="images.length!=0" fontSize="20" iconSize="20" loadingIcon="circle" loadingText="加载中"
					nomoreText="到底啦~" :status="status" />
			</view>
		</view>
	</view>
</template>

<script>
	import works from "../../components/works/works.vue"
	export default {
		components: {
			works
		},
		onReady() {
			// uni.showLoading({
			// 	title: '加载中'
			// });
		},
		data() {
			return {
				creatorId: 0,
				creator: {},
				status: 'nomore',
				page: 1,
				lastPage: 1,
				images: [],
				types: [],
				currentType: 1,
				currentIndex: 0,
				params: {},
				activeStyle: {
					"font-size": "30rpx",
					color: '#303133',
					fontWeight: '600',
					transform: 'scale(1)'
				},
				itemStyle: {
					"font-size": "30rpx",
					"padding-left": "15px",
					"padding-right": "15px",
					"height": "34px"
				},
				inactiveStyle: {
					"font-size": "30rpx",
					color: '#606266',
				}
			}
		},
		onReachBottom() {
			if (this.images.length != 0) {
				this.status = 'loading';
				setTimeout(() => {
					this.page++
					if (this.page <= this.lastPage) {
						this.getWorks()
					} else {
						this.status = 'nomore';
					}
				}, 100)
			}
		},
		onLoad(params) {
			this.creatorId = params.id
			this.getCreatorInfo()
		},
		methods: {
			getCreatorInfo() {
				this.$api.getCreatorInfo(this.creatorId).then((res) => {
					this.creator = res.data
					this.types = this.creator.works_type.types
					this.currentType = this.creator.works_type.default
					this.types.forEach((item, index, arr) => {
						if (item.id == this.currentType) {
							this.currentIndex = index
						}
					})
					this.getWorks('onload')
				})
			},
			getWorks(type) {
				this.status = 'loading';
				this.$api.getWorks(this.creatorId, this.currentType, this.page).then((res) => {
					this.lastPage = res.data.last_page
					// setTimeout(() => {
					// 	uni.hideLoading();
					// }, 100)
					if (res.data.data.length != 0) {
						this.images = [...this.images, ...res.data.data];
					}
					this.status = 'nomore';
				})
			},
			//分类点击
			changeType(param) {
				const type = param.id
				if (type != this.currentType) {
					this.currentType = type
					this.images = []
					this.page = 1
					this.lastPage = 1
					this.getWorks()
				}
			},
			//跳转专辑页面
			toGroup() {
				uni.navigateTo({
					url: "/pages/works/group"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		background-color: #fff;
		min-height: 100vh;
	}

	/deep/ .u-tabs__wrapper__nav__line {
		justify-content: center;
		left: 34rpx;
	}

	.empty {
		height: 100vh;
		margin-top: 50% !important;
	}

	.head-bg {
		width: 100vw;
		height: 440rpx;
	}

	.head {
		position: absolute;
		display: flex;
		box-sizing: border-box;
		padding: 30rpx 20rpx 40rpx;
		width: 100%;
		top: 16%;
		left: 0;
		// background-image: linear-gradient(rgba(255, 255, 255, .3), rgba(0, 0, 0, .6));
		// box-shadow: 1px 1px 10px rgba(255, 255, 255, .6);
		color: #fff;

		image {
			height: 108rpx;
			width: 108rpx;
			border-radius: 50%;
			border: 2px solid #fff;
			margin-right: 20rpx;
		}

		.name {
			padding-top: inherit;
			font-size: 30rpx;
		}

		text {
			padding-right: 20rpx;
			font-size: 20rpx;
			font-size: 20rpx;
		}
	}

	.content {
		box-sizing: border-box;
		position: absolute;
		top: 440rpx;
		left: 0;
		width: 100%;
		// height: 100vh;
		background-color: #fff;
		border-radius: 20rpx;
		margin-top: -20rpx;
		z-index: 999;

		.nums {
			display: flex;
			color: #666;
			margin-top: 20rpx;
			margin-left: 20rpx;

			.item {
				margin-right: 20rpx;
				font-size: 26rpx;
			}

			text {
				color: #000;
				font-weight: 600;
				padding-right: 10rpx;
			}
		}

		.bio {
			margin-top: 20rpx;
			margin-left: 20rpx;
			font-size: 24rpx;
			color: #999;
		}

		.types-content {
			margin-top: 20rpx;
			// padding-bottom: 10rpx;

			.images {
				display: flex;
				flex-wrap: wrap;
				margin-top: 10rpx;

				image {
					width: $uni-img-width + 13;
					height: $uni-img-height;
					margin-right: 10rpx;
					margin-top: 10rpx;
				}
			}
		}
	}
</style>
